let app = getApp();
var applet_park_api_url = app.globalData.applet_park_api_url;
const {
  requestDataparams
} = require('../../../utils/request.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type:'',
    inputValue:'',
    inputBuild:'',
    inputUtil:'',
    waterPayer:'南京水务集团有限公司银行代收',
    electricPayer:'南京供电公司',
    groupName:'请选择分组',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      
      var that = this;
      if(options.type){
        that.setData({
          type:options.type
        })
      }
  },
  entergrouping(){//分组
    wx.navigateTo({
      url: '../grouping/grouping',
    })
  },
  getBuild(e){
    var that = this;
      var value = e.detail.value;
      
      that.setData({
        inputBuild:value
      })
  },
  getUnit(e){
    var that = this;
    var value = e.detail.value;
    
    that.setData({
      inputUnit:value
    })
  },
  getValue(e){
      
      var that = this;
      var value = e.detail.value;
      that.setData({
        inputValue:value
      })
  },
  enterPay(){
   var that = this;
   var type = that.data.type;
   if((that.data.inputValue == '')||(that.data.inputValue == undefined)){
     wx.showToast({
       title: '请先输入户号',
     })
     return false;
   }
   if(type == 'water'){//水费
    that.submitForWater();

   }else if(type == 'electric'){
     that.submitForElectric();
    
   }else{
    that.submitForProperty()
  
   }
   
  },
  submitForWater(){
     var that = this;
     var value = that.data.inputValue;
    requestDataparams('/api/unifiedOrder/queryWaterRateInfo/value',{}, 'POST','json').then(response=>{
                 
                  if(response.data.code == 0){
                    var datas = response.data.data;
                    var accountName = datas.accountName;
                    var accountNumber = value;
                    var address = datas.address;
                    var totalMoney = datas.totalMoney;
                    var unit = datas.unit;
                    wx.navigateTo({
                        url: '../chargeForWater/chargeForWater?accountName='+accountName+'&accountNumber='+accountNumber+'&address='+address+'&totalMoney='+totalMoney+'&unit='+unit,
                      })
                   
                  }else{
                    wx.showToast({
                      title: '失败',
                      icon:'none'
                    })
                  }
          })
  },
  submitForElectric(){
    var that = this;
    var value = that.data.inputValue;
   requestDataparams('/api/unifiedOrder/queryPowerRateInfo/value',{}, 'POST','json').then(response=>{
                
                 if(response.data.code == 0){
                  var datas = response.data.data;
                  var accountName = datas.accountName;
                  var accountNumber = value;
                  var address = datas.address;
                  var totalMoney = datas.totalMoney;
                  var unit = datas.unit;
                  wx.navigateTo({
                    url: '../chargeForElectric/chargeForElectric?accountName='+accountName+'&accountNumber='+accountNumber+'&address='+address+'&totalMoney='+totalMoney+'&unit='+unit,
                  })
                  
                 }else{
                   wx.showToast({
                     title: '失败',
                     icon:'none'
                   })
                 }
         })
  },
  submitForProperty(){
    var that = this;
    var value = that.data.inputValue;
   requestDataparams('/api/unifiedOrder/queryPropertyFeeInfo',{}, 'POST','json').then(response=>{
                
                 if(response.data.code == 0){
                  var datas = response.data.data;
                  var buildAddress = datas.buildAddress;
                  var accountNumber = value;
                  var totalMoney = datas.totalMoney;
                  var unit = that.data.inputUnit;
                  wx.navigateTo({
                    url: '../chargeForProperty/chargeForProperty?buildAddress='+buildAddress+'&totalMoney='+totalMoney+'&unit='+unit+'&accountNumber='+accountNumber,
                  })
                  
                 }else{
                   wx.showToast({
                     title: '失败',
                     icon:'none'
                   })
                 }
         })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})